<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
  /**
   * 首页视图
   */
    public function index($p=1){
      $this->title="「 这里有我的作品与文章欢迎与我交流 」";
      $this->p=$p;
      $this->page=ceil(M('article')->count()/10);
      $this->articles=M('article')->field('content',true)->order('id desc')->limit(($p-1)*10,10)->select();
      $this->display();
    }
    public function search($p=1){
      $this->p=$p;
      $article=M('article');
      $this->title="搜索关键词「".I('get.s').'」的搜索结果';
      $this->page=ceil($article->field('content',true)->where('title like "%'.I('get.s').'%"')->count()/10);
      $this->articles=$article->field('content',true)->where('title like "%'.I('get.s').'%"')->order('id desc')->limit(($p-1)*10,10)->select();
      $this->display("index");
    }
    public function article(){
      if($this->article=M('article')->find(I('get.id')))
        $this->display();
      else $this->display('Public:404');
    }
    //分类文章
    public function articles($p=1){
      $cate=M('category')->find(I('get.cid'));
      $this->title='「 '.$cate['name'].' 」';
      $this->p=$p;
      $article=M('article');
      $this->page=ceil($article->where('cid='.I('get.cid'))->count()/10);
      $this->articles=$article->where('cid='.I('get.cid'))->order('id desc')->limit(($p-1)*10,10)->select();
      $this->display("index");
    }
    //关于我
    public function about(){
      $this->display();
    }
    //留言簿视图
    public function msgpad(){
      $this->display();
    }

    public function works(){
      $this->page=ceil(M('works')->count()/9);
      $this->works=M('works')->order('id desc')->limit(0,9)->select();
      $this->display();
    }
}
